package com.hosp.service;

import java.util.List;

import com.hosp.bean.Sysuser;
import com.hosp.bean.SysuserExample;
import com.hosp.mapper.SysuserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * @author ztranscript 2021/9/11 11:15
 **/
@Service
public class SysLoginService {
    @Autowired
    private SysuserMapper sysuserMapper;

    /**
     * 用户认证
     *
     * @param loginUser 登录用户信息
     * @return 数据库用户
     */
    public Sysuser login(Sysuser loginUser) {
        // 查询数据库
        SysuserExample example = new SysuserExample();
        SysuserExample.Criteria criteria = example.createCriteria();
        criteria.andULoginNameEqualTo(loginUser.getuLoginName());
        criteria.andUPassWordEqualTo(loginUser.getuPassWord());
        List<Sysuser> list = sysuserMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        } else {
            return null;
        }
    }
}
